﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using System.Collections;
using ECCIT;
using ECCIT.Web;
using OgilvyOne.UKNow.Model;
using OgilvyOne.UKNow.BLL;
using System.Data;
using System.IO;
public partial class admin_UKNOW_impression_impression_add : AdminBasePage
{
    private const string VIEWSTATE_COLUMN_ID = "columnid";
    private const string VIEWSTATE_LAYER_ID = "layerid";
    private const string VIEWSTATE_KEY_ID = "kid";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ViewState[VIEWSTATE_COLUMN_ID] = int.Parse(Request.Params[VIEWSTATE_COLUMN_ID]);
            ViewState[VIEWSTATE_LAYER_ID] = Request.Params[VIEWSTATE_LAYER_ID];

            string sKeyID = RequestContext.GetParamValueByParamName(VIEWSTATE_KEY_ID, "");
            ViewState[VIEWSTATE_KEY_ID] = sKeyID;
            if (string.IsNullOrEmpty(sKeyID))
                InitPage(null, 0);
            else
                InitPage(int.Parse(sKeyID), 0);
        }
    }
    private void InitPage(int? sKeyID, int type)
    {
        //InitControls();

        VotesKeyWordsModel model = null;
        if (sKeyID.HasValue)
        {
            VotesKeyWordsBLL bll = new VotesKeyWordsBLL(this.LangID);
            model = bll.selKeyWords(sKeyID.Value);
        }

        BindKeyWordsToControls(model, type);
    }
    private void BindKeyWordsToControls(VotesKeyWordsModel info, int type)
    {
        if (info == null)
        {
            infoname.Text = "新增关键字";
            return;
        }
        infoname.Text = "修改关键字";     
        title.Text = info.Name;
        voteTimes.Text = info.Count.ToString();
        keyType.Text = info.Type.ToString();
        pub.SelectedValue = info.State.ToString();
    }
    protected void Sub_click(object sender, EventArgs e)
    {
        VotesKeyWordsBLL bll = new VotesKeyWordsBLL(this.LangID);
        VotesKeyWordsModel info = new VotesKeyWordsModel();

        info.ID = null;
        if (!string.IsNullOrEmpty(ViewState[VIEWSTATE_KEY_ID].ToString()))
        info.ID = int.Parse(ViewState[VIEWSTATE_KEY_ID].ToString());
        info.Name = title.Text;
        if (keyType.Text == null || keyType.Text == "")
        { info.Type = 1; }
        else{ info.Type=int.Parse(keyType.Text);}
        info.LanguageID=LangID;
        info.State = int.Parse(pub.SelectedValue);
        if (voteTimes.Text==null||voteTimes.Text=="")
        { info.Count = 0; }
        else{info.Count = int.Parse(voteTimes.Text);}
        ResultInfo res = bll.Save(info);
        if (res.Result)
        {
            Response.Redirect("impression_list.aspx?columnid=" + ViewState[VIEWSTATE_COLUMN_ID] + "&layerid=" + ViewState[VIEWSTATE_LAYER_ID] + "&langID=" + LangID);
        }
        else
        {
            Response.Write("<script>alert('保存失败')</script>");
            Response.Write(res.Message);
        }

    }
    protected void lbBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("impression_list.aspx?columnid=" + ViewState[VIEWSTATE_COLUMN_ID] + "&layerid=" + ViewState[VIEWSTATE_LAYER_ID] + "&langID=" + LangID);
    }
}